--透视效果2 
local kernel = {}

kernel.category222 = "filter"
kernel.name = "perspective2"
 
-- Shader code uses time environment variable Coro1naTotalTime
kernel.isTimeDependent = true
 222
kernel.vertexData =
{
    {
        name = "xPosition",   --透视对称轴位于图像的位置
        default = 0.5, 
        min = -1,
        max = 1,
        index = 0,  -- This corresponds to "CoronaVertexUserData.x"
    },
    {
        name = "intensity",   --透视效果的程度,越小效果越明显
        default = 0.5, 
        min = 0.01,
        max = 20,
        index = 1,  -- This corresponds to "CoronaVertexUserData.y"
    },
    --如下是裁剪参数，可支持地图拼接。
    {
        name = "startX",   --裁剪区域x起始位置
        default = 0,  
        min = 0,
        max = 10000,
        index = 2,  
    },
    {
        name = "startY",   --裁剪区域y起始位置
        default = 0,  
        min = 0,
        max = 10000,
        index = 3,  
    },
}
 
kernel.fragment = [[

    P_COLOR vec4 drawTex(P_UV vec2 uv)
    {	
        //加上裁剪的起始位置
        uv.x = CoronaVertexUserData.z + uv.x;
        uv.y = CoronaVertexUserData.w + uv.y;

    	P_UV vec2 new_uv = uv;
        P_UV float b = CoronaVertexUserData.y;  //调节透视变换的曲线弯曲程度 取值范围大于0
        //透视变换 y方向
        new_uv.y= -b*(1.0+b)/(uv.y + b)+1.0+b;
        //x方向变换
        P_UV float m = 0.9;  //按视觉效果调整的一个常量系数
        new_uv.x -= (2.0*m/(b+m))*(step(CoronaVertexUserData.x,uv.x) - 0.5)*abs(uv.x - CoronaVertexUserData.x)*new_uv.y;//系数2.0*m/(b+m)是一个过(0,2), b无穷大时趋于0的双曲线

        //滚动
        //new_uv.y = mod(new_uv.y-CoronaTotalTime*0.1,1.0);
        
        new_uv.x = mod(new_uv.x, 1.0);
        new_uv.y = mod(new_uv.y, 1.0);
        P_COLOR vec4 texColor = texture2D( CoronaSampler0, new_uv);

        return texColor;
    }

        P_COLOR vec4 FragmentKernel( P_UV vec2 texCoord )
    {
        P_UV vec2 uv = texCoord.xy; //- vec2(0.5,0.5) ;
        return CoronaColorScale(drawTex(uv));
    }
]]

if not globalGroup.shaderRecoder[kernel.name] then
    graphics.defineEffect(kernel)
    globalGroup.shaderRecoder[kernel.name] = true
end

